<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>判断图片是否损坏</title>
    <style>
    </style>
</head>
<body>
    <div>
        <img src="./image/1w.jpg" onerror="imgLoadError(this)">
    </div>
    <script>
        function imgLoadError (e) {
            e.src="./image/2.jpg";
        }

        function checkImgExists(imgurl) {
            var ImgObj = new Image() //判断图片是否存在
            ImgObj.src = imgurl;
            ImgObj.onload = function (e) {
                console.log(ImgObj);
                //没有图片，则返回-1
                if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
                    console.log(111)
                    return true
                } else {
                    console.log(222)
                    return false
                }

            }
            
        }
        // let flag = checkImgExists('./image/1222.jpg');
    </script>
</body>
</html>